package com.leetcode.LC;

import java.util.ArrayList;

public class LC897 {

    ArrayList<Integer> list = new ArrayList<>();

    public TreeNode increasingBST(TreeNode root) {
        zhongxuDigui(root);

        TreeNode treeNode = new TreeNode();
        TreeNode tmp=treeNode;
        for (int i = 0; i < list.size(); i++) {
            tmp.val = list.get(i);
            if (i != list.size() - 1) {
                TreeNode rightNode=new TreeNode();
                tmp.right=rightNode;
                tmp=rightNode;
            }
        }
        return treeNode;
    }

    // 用递归的方法进行中序遍历
    public void zhongxuDigui(TreeNode treeNode) {
        if (treeNode.left != null) {
            zhongxuDigui(treeNode.left);
        }
        list.add(treeNode.val);
        if (treeNode.right != null) {
            zhongxuDigui(treeNode.right);
        }
    }
}
